<%--

   Copyright 2020-2021 redragon-erp/赤龙ERP
   Author redragon/dongbin
   This file is part of redragon-erp/赤龙ERP.

     赤龙ERP官方声明：
   (1)赤龙ERP的知识产权归软件著作权人所有
   (2)未经著作权人授权，不得将赤龙ERP用于任何形式的商业用途
   (3)对侵权的组织或个人，著作权人将保留诉诸法律的权利

     赤龙ERP官网详见 <https://www.redragon-erp.com>
     赤龙ERP仓库详见 <https://gitee.com/redragon/redragon-erp> 
     如遇任何问题，请与著作权人联系
	
--%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<%-- 导入面包屑 --%>
<jsp:include page="../common/nav.jsp"></jsp:include>

<div class="wrapper wrapper-content animated fadeInRight">

	<%-- 导入提示信息框 --%>
    <c:if test="${hint!=null&&hint!=''}">
   		<jsp:include page="../common/alert/alert.jsp">
   			<jsp:param value="${hint}" name="alertType"/>
   			<jsp:param value="${alertMessage}" name="alertMessage"/>
   		</jsp:include>
    </c:if>

	<div class="row">
		<div class="col-lg-12">
			<div class="ibox ">
				<div class="ibox-title">
					<h4>通知编辑&nbsp;<span style="color: black;">（<i class="fa fa-tag"></i>${requestScope.approveStatusMap[requestScope.sysNotice.approveStatus]}）</span></h4>
					<div class="ibox-tools">
					</div>
				</div>

				<div class="ibox-content">
					<form id="editForm" action="web/sysNotice/editSysNotice" method="post">
					
						<div class="form-group  row">
							<label class="col-sm-2 col-form-label"><span class="text-danger">*</span>通知编码</label>
							<div class="col-sm-4">
								<input id="noticeCode" name="noticeCode" type="text" class="form-control" value="${requestScope.sysNotice.noticeCode}" readonly="readonly">
							</div>
							
							<label class="col-sm-2 col-form-label"><span class="text-danger">*</span>通知类型</label>
							<div class="col-sm-4">
								<select name="noticeType" id="noticeType" class="form-control">
									<option value="" selected="">请选择</option>
									<c:forEach items="${requestScope.noticeTypeMap}" var="noticeType">
			                       		<option value="${noticeType.key}">${noticeType.value}</option>
			                       	</c:forEach>
								</select>
							</div>
						</div>
						<div class="hr-line-dashed"></div>
						
						<div class="form-group  row">
							<label class="col-sm-2 col-form-label"><span class="text-danger">*</span>业务类型</label>
							<div class="col-sm-4">
								<select name="businessType" id="businessType" class="form-control">
									<option value="" selected="">请选择</option>
									<c:forEach items="${requestScope.businessTypeMap}" var="businessType">
			                       		<option value="${businessType.key}">${businessType.value}</option>
			                       	</c:forEach>
								</select>
							</div>
							
							<label class="col-sm-2 col-form-label"><span class="text-danger">*</span>通知等级</label>
							<div class="col-sm-4">
								<select name="noticeLevel" id="noticeLevel" class="form-control">
									<option value="" selected="">请选择</option>
									<c:forEach items="${requestScope.noticeLevelMap}" var="noticeLevel">
			                       		<option value="${noticeLevel.key}">${noticeLevel.value}</option>
			                       	</c:forEach>
								</select>
							</div>
						</div>
						<div class="hr-line-dashed"></div>
						
						<div class="form-group  row">
							<label class="col-sm-2 col-form-label"><span class="text-danger">*</span>通知给（部门）</label>
							<div class="col-sm-4">
								<select name="publishDepartment" id="publishDepartment" class="chosen-select form-control" multiple >
									<c:forEach items="${requestScope.hrDepartmentList}" var="hrDepartment">
			                       		<option value="${hrDepartment.departmentCode}">${hrDepartment.segmentDesc}</option>
			                       	</c:forEach>
								</select>
							</div>
							
							<label class="col-sm-2 col-form-label"><span class="text-danger">*</span>通知给（职员）</label>
							<div class="col-sm-4">
								<select name="publishPerson" id="publishPerson" class="chosen-select form-control" multiple >
									<c:forEach items="${requestScope.hrStaffList}" var="hrStaff">
			                       		<option value="${hrStaff.staffCode}">${hrStaff.staffName}</option>
			                       	</c:forEach>
								</select>
							</div>
						</div>
						<div class="hr-line-dashed"></div>

						<div class="form-group  row">
							<label class="col-sm-2 col-form-label"><span class="text-danger">*</span>通知标题</label>
							<div class="col-sm-10">
								<input id="title" name="title" type="text" class="form-control" value="${requestScope.sysNotice.title}">
							</div>
						</div>
						<div class="hr-line-dashed"></div>
						

						
						<div class="form-group  row">
							<label class="col-sm-2 col-form-label"><span class="text-danger">*</span>通知内容</label>
							<div class="col-sm-10">
								<textarea id="content" name="content" rows="5" cols="" class="form-control">${requestScope.sysNotice.content}</textarea>
							</div>
						</div>
						<div class="hr-line-dashed"></div>
						
						<!--<div class="form-group  row" style="display: block">
							<label class="col-sm-2 col-form-label"><span class="text-danger">*</span>发布标识</label>
							<div class="col-sm-4">
								<select name="publishFlag" id="publishFlag" class="form-control">
									<option value="" selected="">请选择</option>
									<option value="Y">已发布</option>
									<option value="N">未发布</option>
								</select>
							</div>
							
	                        <label class="col-sm-2 col-form-label"><span class="text-danger">*</span>状态</label>
	
	                        <div class="col-sm-4">
	                        <select class="form-control m-b" name="status" id="status">
	                            <option value="Y" selected="selected">有效</option>
	                            <option value="N">无效</option>
	                        </select>
	                        </div>
						</div>-->
						<div class="hr-line-dashed"></div>
						
						<div class="form-group row">
							<div class="col-sm-12 col-sm-offset-2 text-right">
								<button class="btn btn-white btn-lg" type="button" onclick="window.location.href='web/sysNotice/getSysNoticeList'">返回</button>&nbsp;
								<c:if test="${param.noticeId==null||param.noticeId==''||requestScope.sysNotice.approveStatus=='UNSUBMIT'||requestScope.sysNotice.approveStatus=='REJECT' }">
									<button class="ladda-button ladda-button-demo btn btn-success btn-lg" data-style="expand-right">&nbsp;&nbsp;保存&nbsp;&nbsp;<i class="fa fa-save"></i></button>
								</c:if>
								
								<c:if test="${param.noticeId!=null&&param.noticeId!=''}">
									<c:if test="${requestScope.sysNotice.approveStatus=='UNSUBMIT'||requestScope.sysNotice.approveStatus=='REJECT' }">
										<button class="btn btn-primary btn-lg" type="button" onclick="window.location.href='web/sysNotice/updateApproveStatus?id=${param.noticeId}&approveStatus=SUBMIT'">&nbsp;&nbsp;提交&nbsp;&nbsp;<i class="fa fa-arrow-circle-right"></i></button>&nbsp;
									</c:if>
									<c:if test="${requestScope.sysNotice.approveStatus=='SUBMIT' }">
										<button class="btn btn-warning btn-lg btn-redragon-approve" type="button" onclick="approveData()">&nbsp;&nbsp;审核通过&nbsp;&nbsp;<i class="fa fa-check-circle"></i></button>&nbsp;
										<button class="btn btn-danger btn-lg btn-redragon-approve" type="button" onclick="window.location.href='web/sysNotice/updateApproveStatus?id=${param.noticeId}&approveStatus=REJECT'">&nbsp;&nbsp;驳回&nbsp;&nbsp;<i class="fa fa-times-circle"></i></button>&nbsp;
									</c:if>
									<c:if test="${requestScope.sysNotice.approveStatus=='APPROVE' }">
										<button class="btn btn-success btn-lg" type="button" onclick="alterData()">&nbsp;&nbsp;变更&nbsp;&nbsp;<i class="fa fa-retweet"></i></button>&nbsp;
										<c:if test="${requestScope.sysNotice.publishFlag=='N'&&requestScope.sysNotice.noticeType=='CUSTOM'}">
											<button class="btn btn-primary btn-lg" type="button" onclick="publishData()">&nbsp;&nbsp;发布&nbsp;&nbsp;<i class="fa fa-send-o"></i></button>
										</c:if>
									</c:if>
								</c:if>
							</div>
						</div>
						
						<input type="hidden" name="noticeId" value="${requestScope.sysNotice.noticeId}">
						<input type="hidden" name="createdDate" value="${requestScope.sysNotice.createdDate}">
						<input type="hidden" name="createdBy" value="${requestScope.sysNotice.createdBy}">
					</form>
				</div>
			</div>
		</div>
	</div>
</div>

<!-- Chosen -->
<script src="js/plugins/chosen/chosen.jquery.js"></script>

<script>
	$(document).ready(function() {
		//初始化status
		if("${requestScope.sysNotice.status}"!=""){
			$("#status").val("${requestScope.sysNotice.status}");
		}
		//初始化publishFlag
		if("${requestScope.sysNotice.publishFlag}"!=""){
			$("#publishFlag").val("${requestScope.sysNotice.publishFlag}");
		}
		//初始化noticeType
		if("${requestScope.sysNotice.noticeType}"!=""){
			$("#noticeType").val("${requestScope.sysNotice.noticeType}");
		}
		//初始化businessType
		if("${requestScope.sysNotice.businessType}"!=""){
			$("#businessType").val("${requestScope.sysNotice.businessType}");
		}
		//初始化noticeLevel
		if("${requestScope.sysNotice.noticeLevel}"!=""){
			$("#noticeLevel").val("${requestScope.sysNotice.noticeLevel}");
		}
		//初始化publishDepartment
		if("${requestScope.sysNotice.publishDepartment}"!=""){
			var publishDepartmentStr = "${requestScope.sysNotice.publishDepartment}";
			var publishDepartmentArray = publishDepartmentStr.split(",");
			for(a=0;a<publishDepartmentArray.length;a++){
				$("#publishDepartment option").each(function(){
					if($(this).val()==publishDepartmentArray[a]){
						$(this).prop("selected", true);
					}
				});
			}
		}
		//初始化publishPerson
		if("${requestScope.sysNotice.publishPerson}"!=""){
			var publishPersonStr = "${requestScope.sysNotice.publishPerson}";
			var publishPersonArray = publishPersonStr.split(",");
			for(a=0;a<publishPersonArray.length;a++){
				$("#publishPerson option").each(function(){
					if($(this).val()==publishPersonArray[a]){
						$(this).prop("selected", true);
					}
				});
			}
		}
		

		//发布标识不允许修改
		$("#publishFlag").click(function(){
			redragonJS.alert("发布标识不能修改，审批通过后可手工发布");
		});
		
		//初始化chosen-select
		$('.chosen-select').chosen({width: "100%"});
		
		

		//表单提交	
		var l = $('.ladda-button-demo').ladda();

		l.click(function() {
			$("#editForm").valid();
			//l.ladda('stop');
		});

		$("#editForm").validate({
			rules : {
				noticeCode : {
					required : true,
					isCode : true,
				},
				noticeType : {
					required : true,
				},
				businessType : {
					required : true,
				},
				noticeLevel : {
					required : true,
				},
				title : {
					required : true,
				},
				content : {
					required : true,
				},
				publishFlag : {
					required : true,
				},
				status : {
					required : true,
				},
			},
			submitHandler: function(form) {
				var submitFlag = "Y";
				
				//获取发布到的部门
				var publishDepartmentStr = "";
				$("#publishDepartment option:selected").each(function(){
					if(publishDepartmentStr==""){
						publishDepartmentStr = $(this).val();
					}else{
						publishDepartmentStr = publishDepartmentStr+","+$(this).val();
					}
				});
				
				//获取发布到的职员
				var publishPersonStr = "";
				$("#publishPerson option:selected").each(function(){
					if(publishPersonStr==""){
						publishPersonStr = $(this).val();
					}else{
						publishPersonStr = publishPersonStr+","+$(this).val();
					}
				});
				
				if(publishDepartmentStr==""&&publishPersonStr==""){
					submitFlag = "N";
					redragonJS.alert("通知给（部门或职员）字段必填");
					return false;
				}
				
				//提交
				if(submitFlag=="Y"){
					l.ladda('start');
		        	form.submit();
				}
		    }
		});
	});
	
	//审批通过
	function approveData(){
		redragonJS.confirm("确认审批通过？", function(){
			window.location.href='web/sysNotice/updateApproveStatus?id=${param.noticeId}&approveStatus=APPROVE';
		});
	}
	
	//数据变更
	function alterData(){
		redragonJS.confirm("确认变更数据？", function(){
			window.location.href='web/sysNotice/updateApproveStatus?id=${param.noticeId}&approveStatus=UNSUBMIT';
		});
	}
	
	//发布数据
	function publishData(){
		redragonJS.confirm("确认发布通知？", function(){
			window.location.href='web/sysNotice/publishNotice?id=${param.noticeId}';
		});
	}
</script>